$(function () {
    $('.selectpicker').selectpicker({noneSelectedText:'--请选择--'});
	var partnerId = $('#contractManage input[name="partnerId"]').val();
	$.ajax({
        url: ctx + '/bizContract/selectByPartnerId',
        data: {partnerId:partnerId},
        dataType: 'json',
        type: 'post',
        success: function (data) {
        	$('#contractManage input[name="departmentName"]').val(data.sysDepartment.fullName);
        	$('#contractManage input[name="partnerDepartmentId"]').val(data.departmentId);
        	$('#contractManage input[name="partnerCode"]').val(data.partnerCode);
        	$('#contractManage input[name="partnerName"]').val(data.partnerName);
        	$('#contractManage input[name="partnerShortName"]').val(data.partnerShortName);
        	$('#contractManage input[name="partnerAddress"]').val(data.partnerAddress);
        	var contact = JSON.parse(data.contact);
            var contactDom = "";
            for (var i = 0; i < contact.length; ++i) {
                    contactDom += '<div class="form-group col-sm-12 contactList">' +
                        '<label class="control-label col-sm-2 no-padding-right">联系人名单：</label>' +
                        '<div class="col-sm-10">' +
                        '<div class="col-sm-2 no-padding">' +
                        '<input name="name" class="form-control" value="'+contact[i].name+'" disabled></input>' +
                        '</div>' +
                        '<div class="col-sm-4">' +
                        '<input name="type" class="form-control" value="'+contact[i].type+'" disabled></input>' +
                        '</div>' +
                        '<div class="col-sm-5 no-padding-right">' +
                        '<input name="tel" class="form-control" value="'+contact[i].tel+'" disabled></input>' +
                        '</div>' +
                        '</div>' +
                        '</div>';
            }
            $('#contractManage .contactList').remove();
            $('#contractManage .contact-split').after(contactDom);
            $('#contractManage .contactList').find('.fa-minus-circle').eq(0).css('display', 'none');
            var bankCard = JSON.parse(data.bankCard);
            var bankCardDom = "";
            for (var i = 0; i < bankCard.length; ++i) {
            	bankCardDom += '<div class="form-group col-sm-12 bankCard">' +
                        '<label class="control-label col-sm-2 no-padding-right">银行卡信息：</label>' +
                        '<div class="col-sm-10">' +
                        '<div class="col-sm-2 no-padding">' +
                        '<input type="text" class="form-control" value="'+bankCard[i].bank+'" disabled>' +
                        '</div>' +
                        '<div class="col-sm-4">' +
                        '<input type="text" class="form-control" value="'+bankCard[i].detail+'" disabled>' +
                        '</div>' +
                        '<div class="col-sm-2 no-padding-right">' +
                        '<input type="text" class="form-control" value="'+bankCard[i].user+'" disabled>' +
                        '</div>' +
                        '<div class="col-sm-3 no-padding-right">'+
                        '<input type="text" class="form-control" value="'+bankCard[i].account+'" disabled>'+
                        '</div>'+
                        '</div>' +
                        '</div>';
            }
            $('#contractManage .bankCard').remove();
            $('#contractManage .bankCard-split').after(bankCardDom);
            $('#contractManage .bankCard').find('.fa-minus-circle').eq(0).css('display', 'none');
            var bankReturn = JSON.parse(data.bankReturn);
            var bankReturnDom = "";
            for (var i = 0; i < bankReturn.length; ++i) {
            	bankReturnDom += '<div class="form-group col-sm-12 rebates">' +
                        '<label class="control-label col-sm-2 no-padding-right">返款账号信息：</label>' +
                        '<div class="col-sm-10">' +
                        '<div class="col-sm-2 no-padding">' +
                        '<input type="text" class="form-control" value="'+bankReturn[i].bank+'" disabled>' +
                        '</div>' +
                        '<div class="col-sm-4">' +
                        '<input type="text" class="form-control" value="'+bankReturn[i].detail+'" disabled>' +
                        '</div>' +
                        '<div class="col-sm-2 no-padding-right">' +
                        '<input type="text" class="form-control" value="'+bankReturn[i].user+'" disabled>' +
                        '</div>' +
                        '<div class="col-sm-3 no-padding-right">'+
                        '<input type="text" class="form-control" value="'+bankReturn[i].account+'" disabled>'+
                        '</div>'+
                        '</div>' +
                        '</div>';
            }
            $('#contractManage .rebates').remove();
            $('#contractManage .rebates-split').after(bankReturnDom);
            $('#contractManage .rebates').find('.fa-minus-circle').eq(0).css('display', 'none');
        },
        error: function () {
            toastr.error("系统错误");
        }
    });
//	$('.contractAdd').on('hidden.bs.modal', function () {
//		$('#contractAdd')[0].reset();
//		$('#contractAdd input:hidden').val('');
//		$('#contractAdd .selectpicker').selectpicker('refresh');
////		$('#matchAdd .sysUser').remove();
//		$('#contractAdd').data('bootstrapValidator').resetForm();
//	})
//	$('.contractEdit').on('hidden.bs.modal', function () {
//		$('#contractEdit')[0].reset();
//		$('#contractEdit input:hidden').val('');
//		$('#contractEdit .selectpicker').selectpicker('refresh');
////		$('#matchAdd .sysUser').remove();
//		$('#contractEdit').data('bootstrapValidator').resetForm();
//	})
//	$('.productAdd').on('hidden.bs.modal', function () {
//		$('#productAdd')[0].reset();
//		$('#productAdd input:hidden').val('');
//		$('#productAdd .selectpicker').selectpicker('refresh');
////		$('#matchAdd .sysUser').remove();
//		$('#productAdd').data('bootstrapValidator').resetForm();
//	})
//	$('.productEdit').on('hidden.bs.modal', function () {
//		$('#productEdit')[0].reset();
//		$('#productEdit input:hidden').val('');
//		$('#productEdit .selectpicker').selectpicker('refresh');
////		$('#matchAdd .sysUser').remove();
//		$('#productEdit').data('bootstrapValidator').resetForm();
//	})
	 //日期
    $('.duration').daterangepicker({
        locale : {
            separator:' - ',
            applyLabel : '确定',
            cancelLabel : '取消',
            customRangeLabel : '自定义',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                '七月', '八月', '九月', '十月', '十一月', '十二月' ],
            firstDay : 1
        },
        ranges: {
            '今天': [moment().startOf('day'), moment()],
            '昨天': [moment().subtract(1,'days').startOf('day'), moment().subtract(1,'days').endOf('day')],
            '本周': [moment().startOf("week").add(1,'days'),moment().endOf("week").add(1,'days')],
            '上周': [moment().subtract(1,'weeks').startOf("week").add(1,'days'),moment().subtract(1,'weeks').endOf("week").endOf("week").add(1,'days')],
            '本月': [moment().startOf("month"),moment().endOf("month")],
            '上个月': [moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")],
            '最近7天': [moment().subtract(6,'days'), moment()],
            '最近30天': [moment().subtract(29,'days'), moment()]
        },
        applyClass:'btn-primary',
        alwaysShowCalendars: true,
        autoclose:true
    });
    //多选框
	$('.selectpicker').selectpicker('refresh');
	//初始化项目（学历）
	$.ajax({
        url: ctx + '/bizProject/getAllOption',
        type: 'POST',
        data: {projectType : 2},
        dataType: 'json',
        success: function (data) {
    		var opt = "";
        	for(var i=0; i<data.list.length; i++){
        		opt += "<option value="+data.list[i].projectId+">" + data.list[i].fullName+ "</option>";
        	}
        	$("#projectId").html('<option value="">--请选择--</option>'+opt);
        },
        error: function (response) {
        	toastr.error("系统错误");
        }
    });
	//联动级别
	$('#projectId').change(function(){
		var projectId= $('#projectId :selected').val();
		$.ajax({
	        url: ctx + '/bizProjectLevel/getAllOption',
	        type: 'POST',
	        data: {projectId : projectId},
	        dataType: 'json',
	        success: function (data) {
	    		var level = "";
	        	for(var i=0; i<data.list.length; i++){
	        		level += "<option value="+data.list[i].projectLevelId+">" + data.list[i].levelTitle + "</option>";
	        	}
	        	$("#projectLevelId").html('<option value="">--请选择--</option>'+level);
	        },
	        error: function (response) {
	        	toastr.error("系统错误");
	        }
	    });
	});
	//初始化招生地区
	$.ajax({
        url: ctx + '/department/getAllOption',
        type: 'POST',
        data: {type : 3},
        dataType: 'json',
        success: function (data) {
    		var opt = "";
        	for(var i=0; i<data.list.length; i++){
        		opt += "<option value="+data.list[i].departmentId+">" + data.list[i].fullName+ "</option>";
        	}
        	$("#departmentIds").html(opt);
        	$('.selectpicker').selectpicker('refresh');
        },
        error: function (response) {
        	toastr.error("系统错误");
        }
    });
	//初始化院校
	$.ajax({
        url: ctx + '/bizSchool/getAll',
        type: 'POST',
        dataType: 'json',
        success: function (data) {
    		var opt = "";
        	for(var i=0; i<data.list.length; i++){
        		opt += "<option value="+data.list[i].schoolId+">" + data.list[i].schoolName+ "</option>";
        	}
        	$("#schoolId").html('<option value="">--请选择--</option>'+opt);
        },
        error: function (response) {
        	toastr.error("系统错误");
        }
    });
	//初始化专业
	$.ajax({
        url: ctx + '/bizMajor/getAll',
        type: 'POST',
        dataType: 'json',
        success: function (data) {
    		var opt = "";
        	for(var i=0; i<data.list.length; i++){
        		opt += "<option value="+data.list[i].majorId+">" + data.list[i].majorName+ "</option>";
        	}
        	$("#majorId").html(opt);
        	$('.selectpicker').selectpicker('refresh');
        },
        error: function (response) {
        	toastr.error("系统错误");
        }
    });
	//学历
	$.ajax({
        url: ctx + '/studentAttr/getAllOption',
        type: 'POST',
        data: {attrType : 3},
        dataType: 'json',
        success: function (data) {
    		var opt = "";
        	for(var i=0; i<data.list.length; i++){
        		opt += "<option value="+data.list[i].studentAttrId+">" + data.list[i].typeName+ "</option>";
        	}
        	$("#studentAttrId").html('<option value="">--请选择--</option>'+opt);
        },
        error: function (response) {
        	toastr.error("系统错误");
        }
    });
	//户籍
	$.ajax({
        url: ctx + '/address/getAll',
        type: 'POST',
        dataType: 'json',
        success: function (data) {
    		var opt = "";
        	for(var i=0; i<data.list1.length; i++){
        		opt += "<optgroup label="+data.list1[i].fullName+" id="+data.list1[i].addressId+"></optgroup>";
        	}
        	$('#productAdd select[name="registerLimitId"]').html(opt);
        	for(var j=0; j<data.list2.length; j++){
				var copt = "";
				var pid = data.list2[j].parentId;
				copt +="<option value="+data.list2[j].addressId+">"+data.list2[j].fullName+"</option>";
				$('#'+pid+'').append(copt);
    		}
        	$('.selectpicker').selectpicker('refresh');
        },
        error: function (response) {
        	toastr.error("系统错误");
        }
    });
});
//点击新增产品按钮
$('#addNewProductButton').on('click',function(){
	var addHUJEle =$('#productAdd select[name="registerLimitId"]'); 
	var huJiHtml=addHUJEle.html();
	if(huJiHtml.trim()==''){
		addHUJEle.html($('#productEdit select[name="registerLimitId"]').html());
		$('.selectpicker').selectpicker('refresh');
		$('#productEdit select[name="registerLimitId"]').html('');
	}
});
/**
 * 新增联系人名单、银行卡信息、返款账号信息
 * @param parentEle
 */
function addField(parentEle) {
    $(parentEle).on('click', '.add-button', function () {
        //删除
        if ($(this).is('.fa-minus-circle')) {
            if ($(this).parent().parent().find('label').html() == '') {
                $(this).parent().parent().remove();
            } else {
                $(this).parent().parent().next().find('label').html($(this).parent().parent().find('label').html());
                $(this).parent().parent().remove();
            }
        }
        //新增
        if ($(this).is('.fa-plus-circle')) {
            //联系人名单
            if ($(this).is('.linkmanAdd')) {
                var link = $(this).parent().parent().clone(true);
                $(link).find('input').val('');
                $(link).find('input').eq(0).val("次要");
                $(link).find('.linkmanAdd').show();

                $(this).parent().parent().after(link);
                $(parentEle).find('.contactList:not(:first)').find('label').html('');
            }

            //银行卡信息
            if ($(this).is('.bankcardAdd')) {
                var bankcard = $(this).parent().parent().clone(true);
                $(bankcard).find('input').val('');
                $(bankcard).find('.bankcardAdd').show();

                $(this).parent().parent().after(bankcard);
                $(parentEle).find('.bankCard:not(:first)').find('label').html('');
            }

            //返款账号信息
            if ($(this).is('.rebatesAccount')) {
                var rebatesAccount = $(this).parent().parent().clone(true);
                $(rebatesAccount).find('input').val('');
                $(rebatesAccount).find('.rebatesAccount').show();

                $(this).parent().parent().after(rebatesAccount);
                $(parentEle).find('.rebates:not(:first)').find('label').html('');
            }
        }
    });
}

//合作方新增
addField('.partnerAdd');
//合作方编辑
addField('.partnerEdit');

$('#contractManage').find('.add-button').hide();

//合作方信息编辑
$('.partnerInfo').click(function () {
    //编辑
    if ($(this).find('i').is('.fa-pencil')) {
        $(this).find('i').removeClass('fa-pencil blue').addClass('fa-save success');
        $('#contractManage').find('input,select').removeAttr('disabled');
        $('#contractManage').find('.add-button').show();
        $('#contractManage .contactList:first,#contractManage .bankCard:first,#contractManage .rebates:first').find('.fa-minus-circle').hide();
        addField('#contractManage');
    } else {
        //保存
        $(this).find('i').removeClass('fa-save success').addClass('fa-pencil blue');
        $('#contractManage').find('input,select').attr('disabled', 'disabled');
        $('#contractManage').find('.add-button').hide();
    }
});

/**
 * 新增期次、返款情况
 * @param parentEle
 */
function product(parentEle) {
    $(parentEle).on('click', '.add-field', function () {
        //删除
        if ($(this).is('.fa-minus-circle')) {
            $(this).parent().remove();
        }

        //新增
        if ($(this).is('.fa-plus-circle')) {
            //期次
            if ($(this).hasClass('addIssue')) {
                $(this).parent().find('.time').text($(this).parent().find('.time').text() * 1 + 1);

                var timeAdd = $(this).parent().clone(true);
                $(timeAdd).find('input').val('');
                $(timeAdd).find('.add-field').show().css('top',7);

                $(this).parent().after(timeAdd);
                $(this).parent().find('.time').text($(this).parent().prev().find('.time').text() * 1 + 1);
            }

            //返款情况
            if ($(this).hasClass('addRebates')) {
                $(this).parent().find('.time').text($(this).parent().find('.time').text() * 1 + 1);

                var rebatesAdd = $(this).parent().clone(true);
                $(rebatesAdd).find('input').val('');
                $(rebatesAdd).find('.add-field').show().css('top',7);;


                $(this).parent().after(rebatesAdd);
                $(this).parent().find('.time').text($(this).parent().prev().find('.time').text() * 1 + 1);
            }
        }
    })
}
//产品新增
product('.productAdd');
//产品编辑
product('.productEdit');

//合同信息编辑
$('.contractInfo').click(function () {
    //编辑
    if ($(this).find('i').is('.fa-pencil')) {
        $(this).find('i').removeClass('fa-pencil blue').addClass('fa-save success');
        $('#contractEdit').find('input,select').removeAttr('disabled');
        editor2.readonly(false);
    } else {
        //保存合同信息
        $(this).find('i').removeClass('fa-save success').addClass('fa-pencil blue');
        $('#contractEdit').find('input,select').attr('disabled', 'disabled');
        var uploadContract=editor2.html();
        var contractId = $('#contractEdit').find('#updtcontractId').val();
    	var contractCode = $('#contractEdit').find('#updtContractCode').val();
    	var signUser = $('#contractEdit').find('#updtSignUser').val();
    	var discussUser = $('#contractEdit').find('#updtdiscussUser').val();
    	var duration = $('#contractEdit').find('#updtDuration').val();
    	var signDate = duration.split(" - ")[0];
        var aa = duration.split(" - ")[1];
        var expireDate = aa +" 23:59:59";
        $.ajax({
			url : ctx + '/bizContract/updateRecord',
			data :{contractId,contractCode,signUser,discussUser,signDate,expireDate,uploadContract},
			dataType : 'json',
			type : 'post',
			success : function(data){
				if(data.status != "success"){
					toastr.error(data.msg);
				}else{
					$('.contractEdit').modal('hide');
					DataTable.init();
				}
			},
			error : function(){
				toastr.error("系统错误");
			}
		});
    }
});

//合同新增保存显示增加产品
//$('.contract-save').click(function () {
//    $('.productInfo').show();
//});

//新增合同
$('#contractAdd').bootstrapValidator({
	submitHandler: function (validator, form, submitButton) {
		var params = form.serialize();
		var duration = $('#contractAdd').find('#duration').val();
		var signDate = duration.split("-")[0];
        var expireDate = duration.split("-")[1];
        params += "&signDate=" + signDate;
        params += "&expireDate=" + expireDate +" 23:59:59";
        console.log(params);
//        return;
        $.ajax({
			type: "POST",
            url:  ctx + '/bizContract/addNewRecord',
            data: params,
            dataType: 'json',
            success: function (data) {
            	$('.contractAdd').modal('hide');
            	DataTable.init();
            },
		error: function (msg) {
        	toastr.error("系统错误");
        }
		});
	}
});
//查询合同信息
var DataTable = function(){
	return{
		init: function(){
			var Table = $('#bizContract').dataTable({
				"bPaginate": true,  //是否显示分页
            	"iDisplayLength": 15,
            	"bLengthChange": false,//每页显示的记录数
            	"bFilter": false, //搜索栏
            	"bSort": true, //是否支持排序功能
            	"bInfo": true, //显示表格信息
            	"bAutoWidth": false,  //自适应宽度
            	"bStateSave": true, //保存状态到cookie *************** 很重要 ， 当搜索的时候页面一刷新会导致搜索的消失。使用这个属性就可避免了
            	//"sPaginationType": "", //分页，一共两种样式，full_numbers和two_button(默认)
            	"sAjaxSource" : ctx+'/bizContract/load',
        		"fnServerData": retrieveData,//用于替换默认发到服务端的请求操作  
            	"bServerSide": true,
            	"bDestroy": true,
                "bRetrieve": false,
                "oLanguage" : {
        			"sLengthMenu" : "每页显示 _MENU_ 条记录",
        			"sZeroRecords" : "抱歉， 没有找到",
        			"sInfo" : "从 _START_ 到 _END_ / 共 _TOTAL_ 条数据",
        			"sInfoEmpty" : "找不到相关数据",
        			"sInfoFiltered" : "数据表中共为 _MAX_ 条记录)",
        			"sProcessing": "正在加载中...",
        			"sSearch": "搜索",
        			"oPaginate" : {
        				"sFirst" : "首页",
        				"sPrevious" : "前一页",
        				"sNext" : "后一页",
        				"sLast" : "尾页"
        			},
        		},
        		"aoColumns" : [
        			            {"mData": "contractCode", 'sClass': "text-center"},
        			            {"mData": "discussUser", 'sClass': "text-center"},
        			            {"mData": "signUser", 'sClass': "text-center"},
        			            {"mData": "signDate", 'sClass': "text-center"},
        			            {"mData": "expireDate", 'sClass': "text-center"},
        			            {"mData": "createUserName", 'sClass': "text-center"},
        			            {"mData": "createDate", 'sClass': "text-center"},
//        			            {"mData": "partnerFee", 'sClass': "text-center"},
        			            {"mData": "enable", 'sClass': "text-center","bSortable": false,"mRender":function(data, type, full ){
        			            	if(data==0){
        			          		  return '<span id="span'+full["contractId"]+'" onclick="chooseStudent(\''+full["contractId"]+'\')" class="btn btn-xs btn-nouse"><i class="fa fa-ban"></i> 禁用</span>';
        			          	  }else{
        			          		  return '<span id="span'+full["contractId"]+'" onclick="chooseStudent(\''+full["contractId"]+'\')" class="btn btn-xs btn-use"><i class="fa fa-check-circle-o"></i> 启用</span>';
        			          	  }
        			            }},
        			            {
        			                "mData": "contractId",
        			                'sClass': "text-center",
        			                "bSortable": false,
        			                "mRender": function (data, type, full ) {
        			                   /* var u = '<a onclick="edit(\''+full["contractId"]
		        			                    +'\',\''+full["contractCode"]
		        			                    +'\',\''+full["signUser"]
		        			                    +'\',\''+full["discussUser"]
		        			                    +'\',\''+full["signDate"] 
		        			                    +'\',\''+["expireDate"]
        			                    		+'\',this)" class="btn btn-info btn-xs edit" data-toggle="modal" data-target=".contractEdit" data-backdrop="static" '+(full.enable == 0 ? "disabled" : "")+'><i class="fa fa-edit"></i> 编辑</a>';
        			                    return u;*/
        			                   var e= "<a onclick='edit(this)' data-record='"+JSON.stringify(full)+"' class='btn btn-info btn-xs edit'   data-toggle='modal' data-backdrop='static' data-target='.contractEdit' "+(full.enable == 0 ? 'disabled' : '')+" ><i class='fa fa-edit' ></i> 编辑</a>";
        			                   return e;
        			                }
        			            }
        			        ],
        			        "aoColumnDefs": [{
          		   	            sDefaultContent: '',
          		   	            aTargets: ['_all']
          		   	        }],
			})
		}
	}
}();
DataTable.init();
/**
 * 回调函数
 * @param sSource
 * @param aoData
 * @param fnCallback
 * @returns
 */
function retrieveData( sSource, aoData, fnCallback, oSettings ) {
	aoData.push( { "name": "pageNum", "value": (Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength )+1) });
    aoData.push( { "name": "pageSize", "value": oSettings._iDisplayLength }); 
    var searchVal = $('#searchVal').val();
    if(searchVal && searchVal.length != 0){
    	aoData.push({ "name": "searchVal", "value": searchVal});
    }
    var partnerId = $('#contractManage input[name="partnerId"]').val();
    aoData.push({ "name": "partnerId", "value": partnerId});
    $.ajax({  
        "url": sSource,  
        "data": aoData,  
        "cache": false,  
        "dataType": 'json', 
        "type": "POST", 
        "success" :function(response) {
        	fnCallback(response.returnObject);
        }  
    } );  
};
//修改状态(合同)
function chooseStudent(val,flag){
	var attr = $("#span"+val).attr("class");
	if(attr == "btn btn-xs btn-nouse"){
		flag = 1;
	}else{
		flag = 0;
	}
	$.ajax({
        url: ctx + '/bizContract/updateRecord',
        type: 'POST',
        data: {
        	contractId:val,
        	enable:flag
        },
        dataType: 'json',
        success: function (data) {
        	if(data.status == 'success' && flag == 1){
        		$("#span"+val).removeClass("btn-nouse").addClass("btn-use");
        		$("#span"+val).html('<i class="fa fa-check-circle-o"></i> 启用');
        	}
        	if(data.status == 'success' && flag == 0){
        		$("#span"+val).removeClass("btn-use").addClass("btn-nouse");
        		$("#span"+val).html('<i class="fa fa-ban"></i> 禁用');
        	}
        }
	});
}

var cpDataTable;

//编辑操作
function edit(obj){
	var contract=JSON.parse($(obj).attr('data-record'));
	editor2.readonly(true);
	editor2.html(contract.uploadContract);
	$('#updtcontractId').val(contract.contractId);
	$('#updtContractCode').val(contract.contractCode);
	$('#updtSignUser').val(contract.signUser);
	$('#updtdiscussUser').val(contract.discussUser);
	var signDate = contract.signDate;
	var expireDate = contract.expireDate;
	$('#updtDuration').val(signDate+' - '+expireDate);
	var aa = contract.contractId;
	//查询产品信息
	cpDataTable = function(){
		return{
			init: function(){
				var Table = $('#contractCetail').dataTable({
					"bPaginate": true,  //是否显示分页
	            	"iDisplayLength": 15,
	            	"bLengthChange": false,//每页显示的记录数
	            	"bFilter": false, //搜索栏
	            	"bSort": true, //是否支持排序功能
	            	"bInfo": true, //显示表格信息
	            	"bAutoWidth": false,  //自适应宽度
	            	"bStateSave": true, //保存状态到cookie *************** 很重要 ， 当搜索的时候页面一刷新会导致搜索的消失。使用这个属性就可避免了
	            	//"sPaginationType": "", //分页，一共两种样式，full_numbers和two_button(默认)
	            	"sAjaxSource" : ctx+'/bizContractDetail/load',
	        		"fnServerData": cpRetrieveData,//用于替换默认发到服务端的请求操作  
	            	"bServerSide": true,
	            	"bDestroy": true,
	                "bRetrieve": false,
	                "oLanguage" : {
	    			"sLengthMenu" : "每页显示 _MENU_ 条记录",
	    			"sZeroRecords" : "抱歉， 没有找到",
	    			"sInfo" : "从 _START_ 到 _END_ / 共 _TOTAL_ 条数据",
	    			"sInfoEmpty" : "找不到相关数据",
	    			"sInfoFiltered" : "数据表中共为 _MAX_ 条记录)",
	    			"sProcessing": "正在加载中...",
	    			"sSearch": "搜索",
	    			"oPaginate" : {
	    				"sFirst" : "首页",
	    				"sPrevious" : "前一页",
	    				"sNext" : "后一页",
	    				"sLast" : "尾页"
	    			},
	    		},
	    		"aoColumns" : [
	   			            {"mData": "bizProject.fullName", 'sClass': "text-center"},
//	   			            {"mData": "contractDetailId", 'sClass': "text-center"},
	   			            {"mData": "teachForm", 'sClass': "text-center"},
	   			            {"mData": "bizProjectLevel.levelTitle", 'sClass': "text-center"},
	   			            {"mData": "schoolName", 'sClass': "text-center"},
	   			            {"mData": "bizSchool.schoolName", 'sClass': "text-center"},
	   			            {"mData": "majorName", 'sClass': "text-center"},
	   			            {"mData": "enable", 'sClass': "text-center","bSortable": false,"mRender":function(data, type, full ){
	   			            	if(data==0){
	   			          		  return '<span id="span'+full["contractDetailId"]+'" onclick="chooseStudentCp(\''+full["contractDetailId"]+'\')" class="btn btn-xs btn-nouse"><i class="fa fa-ban"></i> 禁用</span>';
	   			          	  }else{
	   			          		  return '<span id="span'+full["contractDetailId"]+'" onclick="chooseStudentCp(\''+full["contractDetailId"]+'\')" class="btn btn-xs btn-use"><i class="fa fa-check-circle-o"></i> 启用</span>';
	   			          	  }
	   			            }},
	   			            {
	   			                "mData": "contractDetailId",
	   			                'sClass': "text-center",
	   			                "bSortable": false,
	   			                "mRender": function (data, type, full ) {
	   			                    return "<a href='#' data-record='" + JSON.stringify(full) + "' class='btn btn-info btn-xs edit' data-toggle='modal' data-target='.productEdit' data-backdrop='static' "+(full.enable == 0 ? 'disabled' : '')+"><i class='fa fa-edit'></i> 编辑</a>";
	   			                }
	   			            }
	   			        ],
	   			        "aoColumnDefs": [{
	     		   	            sDefaultContent: '',
	     		   	            aTargets: ['_all']
	     		   	        }],
	     		   	    "fnRowCallback":function(nRow,aData,iDisplayIndex){
	     		   	    	if(aData.teachForm=='1'){
			   	        		$('td:eq(1)',nRow).html('自考');
			   	        	}else if(aData.teachForm=='2'){
			   	        		$('td:eq(1)',nRow).html('远程');
			   	        	}else if(aData.teachForm=='3'){
			   	        		$('td:eq(1)',nRow).html('成考');
			   	        	}
	     		   	    	return nRow;
	     		   	    }
				})
			}
		}
	}();
cpDataTable.init();
	/**
	 * 回调函数
	 * @param sSource
	 * @param aoData
	 * @param fnCallback
	 * @returns
	 */
	function cpRetrieveData( sSource, aoData, fnCallback, oSettings ) {
		var contractId = aa;
		aoData.push( { "name": "pageNum", "value": (Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength )+1) });
	    aoData.push( { "name": "pageSize", "value": oSettings._iDisplayLength });  
	    var searchVal = $('#searchVal').val();
	    if(searchVal && searchVal.length != 0){
	    	aoData.push({ "name": "searchVal", "value": searchVal});
	    }
	    aoData.push({"name": "contractId", "value":contractId});
	    $.ajax( {  
	        "url": sSource,  
	        "data": aoData,  
	        "cache": false,  
	        "dataType": 'json', 
	        "type": "POST", 
	        "success" :function(response) {
	        	fnCallback(response.returnObject);
	        }  
	    } );  
	};
	//新增合同产品 
	$('#productAdd').bootstrapValidator({submitHandler: function (validator, form, submitButton) {
			var contractId = aa;
			//是否需要刷身份证
			var isBrushcard = [];
			var isBrushcardObj = {};
			isBrushcardObj['ruxue'] = $('#productAdd select[name="ruxue"]').val();
    			isBrushcardObj['qmks'] = $('#productAdd select[name="qmks"]').val();
			isBrushcardObj['lunwen'] = $('#productAdd select[name="lunwen"]').val();
			isBrushcard.push(isBrushcardObj);
			//是否本人参加考试
			var isSelftest = [];
			var isSelftestObj = {};
			isSelftestObj['rxce'] = $('#productAdd select[name="rxce"]').val();
			isSelftestObj['qmkss'] = $('#productAdd select[name="qmkss"]').val();
			isSelftestObj['wszy'] = $('#productAdd select[name="wszy"]').val();
			isSelftestObj['bylw'] = $('#productAdd select[name="bylw"]').val();
			isSelftestObj['tongkao'] = $('#productAdd select[name="tongkao"]').val();
			isSelftestObj['xwyy'] = $('#productAdd select[name="xwyy"]').val();
			isSelftestObj['zxf'] = $('#productAdd input[name="zxf"]').val();
			isSelftestObj['hzcb'] = $('#productAdd input[name="hzcb"]').val();
			isSelftestObj['ywfd'] = $('#productAdd select[name="ywfd"]').val();
			isSelftest.push(isSelftestObj);
			//费用是否包含以下项目
			var isContain = [];
			var isContainObj = {};
			isContainObj['bmf'] = $('#productAdd select[name="bmf"]').val();
			isContainObj['rxcsf'] = $('#productAdd select[name="rxcsf"]').val();
			isContainObj['zy'] = $('#productAdd select[name="zy"]').val();
			isContainObj['ksf'] = $('#productAdd select[name="ksf"]').val();
			isContainObj['lwdb'] = $('#productAdd select[name="lwdb"]').val();
			isContainObj['tkbm'] = $('#productAdd select[name="tkbm"]').val();
			isContainObj['bkf'] = $('#productAdd select[name="bkf"]').val();
			isContainObj['xwks'] = $('#productAdd select[name="xwks"]').val();
			isContainObj['xwfd'] = $('#productAdd select[name="xwfd"]').val();
			isContainObj['zpcj'] = $('#productAdd select[name="zpcj"]').val();
			isContainObj['sbjg'] = $('#productAdd select[name="sbjg"]').val();
			isContain.push(isContainObj);
			//期次付费
			var payment = []; 
			$('#productAdd input[name="fksj"]').each(function () {
				 var i = $(this).index('#productAdd input[name="fksj"]');
				 var paymentObj = {};
				 paymentObj["fksj"] = $(this).val();
				 paymentObj['fkje'] = $('#productAdd input[name="fkje"]').eq(i).val();
				 paymentObj['bz'] = $('#productAdd input[name="bz"]').eq(i).val();
				 payment.push(paymentObj);
			})
			//返款情况
			var clause = [];
			$('#productAdd input[name="fkbl"]').each(function () {
				var i = $(this).index('#productAdd input[name="fkbl"]');
				var returnStatusObj = {};
				returnStatusObj['fkbl'] = $(this).val();
				returnStatusObj['fktime'] = $('#productAdd input[name="fktime"]').eq(i).val();
				returnStatusObj['fankuanje'] = $('#productAdd input[name="fankuanje"]').eq(i).val();
				returnStatusObj['benzhu'] = $('#productAdd input[name="benzhu"]').eq(i).val();
				clause.push(returnStatusObj);
			})
			var registerLimit =$('#productAdd select[name="registerLimitId"]').siblings('button').attr('title');
			var schoolName =$('#productAdd select[name="departmentIds"]').siblings('button').attr('title');
			var majorName =$('#productAdd select[name="majorId"]').siblings('button').attr('title');
			var params = form.serialize();
			params += "&isBrushcard=" + JSON.stringify(isBrushcard);
			params += "&isSelftest=" + JSON.stringify(isSelftest);
			params += "&isContain=" + JSON.stringify(isContain);
			params += "&payment=" + JSON.stringify(payment);
			params += "&clause=" + JSON.stringify(clause);
			params += "&registerLimit=" + registerLimit;
			params += "&schoolName=" + schoolName;
			params += "&majorName=" + majorName;
			params += "&contractId=" + contractId;
			console.log(params);
			$.ajax({
		        url: ctx + '/bizContractDetail/addNewRecord',
		        data: params,
		        dataType: 'json',
		        type: 'post',
		        success: function (data) {
		            if (data.status != "success") {
		                toastr.error(data.msg);
		            } else {
		                $('.productAdd').modal('hide');
		                $('.contractEdit').modal('hide');
		            }
		        },
		        error: function () {
		            toastr.error("系统错误");
		        }
		    });
			
			return false;
		}
	});
}

//修改状态(合同) 
function chooseStudent(val,flag){
	var attr = $("#span"+val).attr("class");
	if(attr == "btn btn-xs btn-nouse"){
		flag = 1;
	}else{
		flag = 0;
	}
	$.ajax({
        url: ctx + '/bizContract/updateRecord',
        type: 'POST',
        data: {
        	contractId:val,
        	enable:flag
        },
        dataType: 'json',
        success: function (data) {
        	/*if(data.status == 'success' && flag == 1){
        		$("#span"+val).removeClass("btn-nouse").addClass("btn-use");
        		$("#span"+val).html('<i class="fa fa-check-circle-o"></i> 启用');
        	}
        	if(data.status == 'success' && flag == 0){
        		$("#span"+val).removeClass("btn-use").addClass("btn-nouse");
        		$("#span"+val).html('<i class="fa fa-ban"></i> 禁用');
        	}*/
        	DataTable.init();
        }
	});
}
//修改状态(产品) 
function chooseStudentCp(val,flag){
	var attr = $("#span"+val).attr("class");
	if(attr == "btn btn-xs btn-nouse"){
		flag = 1;
	}else{
		flag = 0;
	}
	$.ajax({
        url: ctx + '/bizContractDetail/updateRecord',
        type: 'POST',
        data: {
        	contractDetailId:val,
        	enable:flag
        },
        dataType: 'json',
        success: function (data) {
        	/*if(data.status == 'success' && flag == 1){
        		$("#span"+val).removeClass("btn-nouse").addClass("btn-use");
        		$("#span"+val).html('<i class="fa fa-check-circle-o"></i> 启用');
        	}
        	if(data.status == 'success' && flag == 0){
        		$("#span"+val).removeClass("btn-use").addClass("btn-nouse");
        		$("#span"+val).html('<i class="fa fa-ban"></i> 禁用');
        	}*/
        	cpDataTable.init();
        }
	});
}

//产品编辑
$('#contractCetail').on('click', '.edit', function () {
	var record = $(this).data('record');
	var projectId = record.projectId;
	var projectLevelId = record.projectLevelId; 
	$('#productEdit input[name="projectName"]').val(record.bizProject.fullName);
	$('#productEdit input[name="projectId"]').val(record.projectId);
	$('#productEdit input[name="contractDetailId"]').val(record.contractDetailId);
	$.ajax({
		url: ctx + '/bizProjectLevel/getAllOption',
		type: 'POST',
		data: {"projectId" : projectId}, 
		dataType: 'json',
		async:true,
		success: function (data) {
			var opt = "";
        	for(var i=0; i<data.list.length; i++){
        		opt += "<option value="+data.list[i].projectLevelId+">" + data.list[i].levelTitle+ "</option>";
        	}
        	$("#projectLevelIdUpdt").html(opt);
        	$("#projectLevelIdUpdt").val(projectLevelId);
		},
		error: function (response) {
        	toastr.error("系统错误");
        }
	});
	 $('#productEdit select[name="educationForm"]').val(record.teachForm);
	 var departmentIds = record.departmentIds;
	 $.ajax({
	        url: ctx + '/department/getAllOption',
	        type: 'POST', 
	        data: {type : 3},
	        dataType: 'json',
	        success: function (data) {projectLevelId
	    		var opt = "";
	        	for(var i=0; i<data.list.length; i++){
	        		opt += "<option value="+data.list[i].departmentId+">" + data.list[i].fullName+ "</option>";
	        	}
	        	$("#departmentIdsUpdt").html(opt);
	        	$("#departmentIdsUpdt").selectpicker('val', departmentIds.indexOf(",")?departmentIds.split(','):departmentIds);
	        	$('.selectpicker').selectpicker('refresh');
	        },
	        error: function (response) {
	        	toastr.error("系统错误");
	        }
	    });
	 var schoolId = record.schoolId;
	 $.ajax({
	        url: ctx + '/bizSchool/getAll',
	        type: 'POST',
	        dataType: 'json',
	        success: function (data) {
	    		var opt = "";
	        	for(var i=0; i<data.list.length; i++){
	        		opt += "<option value="+data.list[i].schoolId+">" + data.list[i].schoolName+ "</option>";
	        	}
	        	$("#schoolIdUpdt").html(opt);
	        	$("#schoolIdUpdt").val(schoolId);
	        },
	        error: function (response) {
	        	toastr.error("系统错误");
	        }
	    });
	 var majorId = record.majorId;
	 $.ajax({
	        url: ctx + '/bizMajor/getAll',
	        type: 'POST',
	        dataType: 'json',
	        success: function (data) {
	    		var opt = "";
	        	for(var i=0; i<data.list.length; i++){
	        		opt += "<option value="+data.list[i].majorId+">" + data.list[i].majorName+ "</option>";
	        	}
	        	$("#majorIdUpdt").html(opt);
	        	$("#majorIdUpdt").selectpicker('val', majorId.indexOf(",")?majorId.split(','):majorId);
	        	$('.selectpicker').selectpicker('refresh');
	        },
	        error: function (response) {
	        	toastr.error("系统错误");
	        }
	    });
	 $('#productEdit select[name="serviceForms"]').val(record.serviceType);
	 $('#productEdit input[name="age"]').val(record.age);
	 var studentAttrId = record.studentAttrId;
	 $.ajax({
	        url: ctx + '/studentAttr/getAllOption',
	        type: 'POST',
	        data: {attrType : 3},
	        dataType: 'json',
	        success: function (data) {
	    		var opt = "";
	        	for(var i=0; i<data.list.length; i++){
	        		opt += "<option value="+data.list[i].studentAttrId+">" + data.list[i].typeName+ "</option>";
	        	}
	        	$("#studentAttrIdUpdt").html(opt);
	        	$("#studentAttrIdUpdt").val(studentAttrId);
	        },
	        error: function (response) {
	        	toastr.error("系统错误");
	        }
	    });
	 var registerLimitId = record.registerLimitId;
	 var editHuJEle =$('#productEdit select[name="registerLimitId"]');
	 var editHuJHtml =editHuJEle.html();
	 console.log('editHuJHtml:'+editHuJHtml);
	 if(editHuJHtml.trim()==''){
		 editHuJEle.html($('#productAdd select[name="registerLimitId"]').html());
		 $('.selectpicker').selectpicker('refresh');
		 $('#productAdd select[name="registerLimitId"]').html('');
		  
	 }
	 $('#productEdit select[name="registerLimitId"]').selectpicker('val', registerLimitId.indexOf(",")?registerLimitId.split(','):registerLimitId);
	 $('#productEdit input[name="extraLimit"]').val(record.extraLimit);
	 var isBrushcardJson =JSON.parse(record.isBrushcard);
	 $('#productEdit select[name="professionaProject"]').val(isBrushcardJson[0].ruxue);
	 $('#productEdit select[name="final"]').val(isBrushcardJson[0].qmks);
	 $('#productEdit select[name="paper"]').val(isBrushcardJson[0].lunwen);
	 var isSelftestJson = JSON.parse(record.isSelftest);
	 $('#productEdit select[name="test"]').val(isSelftestJson[0].rxce);
	 $('#productEdit select[name="finalExam"]').val(isSelftestJson[0].qmkss);
	 $('#productEdit select[name="onlineExercise"]').val(isSelftestJson[0].wszy);
	 $('#productEdit select[name="thesis"]').val(isSelftestJson[0].bylw);
	 $('#productEdit select[name="examination"]').val(isSelftestJson[0].tongkao);
	 $('#productEdit select[name="degreeEnglish"]').val(isSelftestJson[0].xwyy);
	 $('#productEdit input[name="tuition"]').val(isSelftestJson[0].zxf);
	 $('#productEdit input[name="costing"]').val(isSelftestJson[0].hzcb);
	 $('#productEdit select[name="rebate"]').val(isSelftestJson[0].ywfd);
	 var isContainJson = JSON.parse(record.isContain);
	 $('#productEdit select[name="bmf"]').val(isContainJson[0].bmf);
	 $('#productEdit select[name="rxcsf"]').val(isContainJson[0].rxcsf);
	 $('#productEdit select[name="zy"]').val(isContainJson[0].zy);
	 $('#productEdit select[name="ksf"]').val(isContainJson[0].ksf);
	 $('#productEdit select[name="lwdbps"]').val(isContainJson[0].lwdb);
	 $('#productEdit select[name="tkbm"]').val(isContainJson[0].tkbm);
	 $('#productEdit select[name="bkf"]').val(isContainJson[0].bkf);
	 $('#productEdit select[name="xwksbm"]').val(isContainJson[0].xwks);
	 $('#productEdit select[name="xwfdf"]').val(isContainJson[0].xwfd);
	 $('#productEdit select[name="zpcjf"]').val(isContainJson[0].zpcj);
	 $('#productEdit select[name="zsgbf"]').val(isContainJson[0].sbjg);
	 var paymentJson = JSON.parse(record.payment);
	 var paymentDom = "";
	 for (var i = 0; i < paymentJson.length; ++i) {
		 paymentDom += '<div class="col-sm-12 paymentIssue no-padding payment">'+
		 					'<div class="form-group col-sm-4">'+
		 						'<label class="control-label col-sm-5 no-padding-right no-padding-left">付款时间</label>'+
		 						'<div class="col-sm-7"><input type="text" name="fksj" class="form-control" value="'+paymentJson[i].fksj+'"></div>'+
		 					'</div>'+	
		 					'<div class="form-group col-sm-4">'+
		 						'<label class="control-label col-sm-5 no-padding-right">付款金额：</label>'+
		 						'<div class="col-sm-7"><input type="text" name="fkje" class="form-control" value="'+paymentJson[i].fkje+'"></div>'+
		 					'</div>'+
		 					'<div class="form-group col-sm-4">'+
		 						'<label class="control-label col-sm-5 no-padding-right paymentRemark">备注：</label>'+
		 						'<div class="col-sm-7"><input type="text" name="bz" class="form-control" value="'+paymentJson[i].bz+'"></div>'+
		 					'</div>'+
		 					'<i class="fa fa-plus-circle blue add-field addIssue control-label"></i>'+
		 					'<i class="fa fa-minus-circle danger add-field control-label" style="display:inline"></i></div>'+
		 				'</div>'	
	 }
	 if(paymentDom != ""){
     	$('#productEdit .payment').remove();
        $('#productEdit .payment-split').after(paymentDom);
     }
	 $('#productEdit .payment').find('.fa-minus-circle').eq(0).css('display', 'none');
	 var clauseJson = JSON.parse(record.clause);
	 var clauseDom = "";
	 for (var i = 0; i < clauseJson.length; ++i) {
		 clauseDom+='<div class="col-sm-12 refundSituation no-padding returnStatus">'+
		 				'<div class="form-group col-sm-4"><label class="control-label col-sm-5 no-padding-right no-padding-left">返款比例：'+
		 				'</label><div class="col-sm-7"><input type="text" name="fkbl" class="form-control" value="'+clauseJson[i].fkbl+'"></div></div>'+
		 				'<div class="form-group col-sm-4"><label class="control-label col-sm-5 no-padding-right">返款时间：</label>'+
		 				'<div class="col-sm-7"><input type="text" name="fktime" class="form-control" value="'+clauseJson[i].fktime+'"></div></div>'+
		 				'<div class="form-group col-sm-4 padding-right-2"><label class="control-label col-sm-5 no-padding-right paymentAmount">付款金额：</label>'+
		 				'<div class="col-sm-7"><input type="text" name="fankuanje" class="form-control" value="'+clauseJson[i].fankuanje+'"></div></div>'+
		 				'<i class="fa fa-plus-circle blue add-field addRebates control-label"></i>'+
		 				'<i class="fa fa-minus-circle danger add-field control-label" style="display:inline"></i>'+
		 				'<div class="form-group col-sm-12"><label class="control-label col-sm-2 no-padding-right common-label">备注：</label>'+
		 				'<div class="col-sm-10 common-10 no-padding-right remarks"><input type="text" name="benzhu" class="form-control" value="'+clauseJson[i].benzhu+'"></div></div></div>'
	 }
	 if(clauseDom != ""){
	     	$('#productEdit .returnStatus').remove();
	        $('#productEdit .returnStatus-split').after(clauseDom);
	     }
		 $('#productEdit .returnStatus').find('.fa-minus-circle').eq(0).css('display', 'none');
});
//产品编辑保存
function validateForm(form, callback, confirmMsg){
	var params = {};
	var contractDetailId = $('#productEdit input[name="contractDetailId"]').val();
	var projectId = $('#productEdit input[name="projectId"]').val();
	var projectLevelId = $('#productEdit select[name="projectLevelId"]').val();
	var teachForm = $('#productEdit select[name="teachForm"]').val();
	var departmentId = $('#productEdit select[name="departmentIds"]').val();
	var aa = "";
	for(var i = 0; i < departmentId.length; i++){
		aa += departmentId[i] + ",";
	}
	var departmentIds = aa.substring(0,aa.length-1);
	var schoolName =$('#productEdit select[name="departmentIds"]').siblings('button').attr('title');
	var schoolId = $('#productEdit select[name="schoolId"]').val();
	var major = $('#productEdit select[name="majorId"]').val();
	var bb = "";
	for(var i = 0; i < major.length; i++){
		bb += major[i] + ",";
	}
	var majorId = bb.substring(0,bb.length-1);
	var majorName =$('#productEdit select[name="majorId"]').siblings('button').attr('title');
	var serviceType = $('#productEdit select[name="serviceType"]').val();
	var age = $('#productEdit input[name="age"]').val();
	var studentAttrId = $('#productEdit select[name="studentAttrId"]').val();
	var registerLimita = $('#productEdit select[name="registerLimitId"]').val();
	var cc = "";
	for(var i = 0; i < registerLimita.length; i++){
		cc += registerLimita[i] + ",";
	}
	var registerLimitId = cc.substring(0,cc.length-1);
	var registerLimit =$('#productEdit select[name="registerLimitId"]').siblings('button').attr('title');
	var extraLimit = $('#productEdit input[name="extraLimit"]').val();
	//是否需要刷身份证
	var isBrushcard = [];
	var isBrushcardObj = {};
	isBrushcardObj['ruxue'] = $('#productEdit select[name="professionaProject"]').val();
	isBrushcardObj['qmks'] = $('#productEdit select[name="final"]').val();
	isBrushcardObj['lunwen'] = $('#productEdit select[name="paper"]').val();
	isBrushcard.push(isBrushcardObj);
	//是否本人参加考试
	var isSelftest = [];
	var isSelftestObj = {};
	isSelftestObj['rxce'] = $('#productEdit select[name="test"]').val();
	isSelftestObj['qmkss'] = $('#productEdit select[name="finalExam"]').val();
	isSelftestObj['wszy'] = $('#productEdit select[name="onlineExercise"]').val();
	isSelftestObj['bylw'] = $('#productEdit select[name="thesis"]').val();
	isSelftestObj['tongkao'] = $('#productEdit select[name="examination"]').val();
	isSelftestObj['xwyy'] = $('#productEdit select[name="degreeEnglish"]').val();
	isSelftestObj['zxf'] = $('#productEdit input[name="tuition"]').val();
	isSelftestObj['hzcb'] = $('#productEdit input[name="costing"]').val();
	isSelftestObj['ywfd'] = $('#productEdit select[name="rebate"]').val();
	isSelftest.push(isSelftestObj);
	//费用是否包含以下项目
	var isContain = [];
	var isContainObj = {};
	isContainObj['bmf'] = $('#productEdit select[name="bmf"]').val();
	isContainObj['rxcsf'] = $('#productEdit select[name="rxcsf"]').val();
	isContainObj['zy'] = $('#productEdit select[name="zy"]').val();
	isContainObj['ksf'] = $('#productEdit select[name="ksf"]').val();
	isContainObj['lwdb'] = $('#productEdit select[name="lwdbps"]').val();
	isContainObj['tkbm'] = $('#productEdit select[name="tkbm"]').val();
	isContainObj['bkf'] = $('#productEdit select[name="bkf"]').val();
	isContainObj['xwks'] = $('#productEdit select[name="xwksbm"]').val();
	isContainObj['xwfd'] = $('#productEdit select[name="xwfdf"]').val();
	isContainObj['zpcj'] = $('#productEdit select[name="zpcjf"]').val();
	isContainObj['sbjg'] = $('#productEdit select[name="zsgbf"]').val();
	isContain.push(isContainObj);
	//期次付费
	var payment = []; 
	$('#productEdit input[name="fksj"]').each(function () {
		 var i = $(this).index('#productAdd input[name="fksj"]');
		 var paymentObj = {};
		 paymentObj["fksj"] = $(this).val();
		 paymentObj['fkje'] = $('#productEdit input[name="fkje"]').eq(i).val();
		 paymentObj['bz'] = $('#productEdit input[name="bz"]').eq(i).val();
		 payment.push(paymentObj);
	})
	//返款情况
		var returnStatus = [];
		$('#productEdit input[name="fkbl"]').each(function () {
			var i = $(this).index('#productEdit input[name="fkbl"]');
			var returnStatusObj = {};
			returnStatusObj['fkbl'] = $('#productEdit input[name="fkbl"]').eq(i).val();
			returnStatusObj['fktime'] = $('#productEdit input[name="fktime"]').eq(i).val();
			returnStatusObj['fankuanje'] = $('#productEdit input[name="fankuanje"]').eq(i).val();
			returnStatusObj['benzhu'] = $('#productEdit input[name="benzhu"]').eq(i).val();
			returnStatus.push(returnStatusObj);
		})
	
	
	params['contractDetailId'] = contractDetailId;
	params['projectId'] = projectId;
	params['projectLevelId'] = projectLevelId;
	params['teachForm'] = teachForm;
	params['departmentIds'] = departmentIds;
	params['schoolName'] = schoolName;
	params['schoolId'] = schoolId;
	params['majorId'] = majorId;
	params['majorName'] = majorName;
	params['serviceType'] = serviceType;
	params['age'] = age;
	params['studentAttrId'] = studentAttrId;
	params['registerLimitId'] = registerLimitId;
	params['registerLimit'] = registerLimit;
	params['extraLimit'] = extraLimit;
	params['isBrushcard'] = JSON.stringify(isBrushcard);
	params['isSelftest'] = JSON.stringify(isSelftest);
	params['isContain'] = JSON.stringify(isContain);
	params['payment'] = JSON.stringify(payment);
	params['clause'] = JSON.stringify(returnStatus);
	$.ajax({
        url: ctx + '/bizContractDetail/updateRecord',
        data: params,
        dataType: 'json',
        type: 'post',
        success: function (data) {
            if (data.status != "success") {
                toastr.error(data.msg);
            } else {
                $('.productEdit').modal('hide');
                $('.contractAdd').modal('hide');
                $('.contractEdit').modal('hide');
                DataTable.init();
            }
        },
        error: function () {
            toastr.error("系统错误");
        }
    });
	return false;
}
function clearForm(){
	$('#contractAdd')[0].reset();//不清除隐藏域
	editor.html('');
}